#include<iostream>
#include<cstring>
#include<algorithm>

using namespace std;
const int N = 510, M = 1e4 + 10;
int dis[N];
int backup[N];
struct Edge
{
	int a, b, w;
}edge[M];
int n, m, k;

int bellman_ford()
{
	memset(dis, 0x3f, sizeof(dis));
	dis[1] = 0;
	for (int i = 0; i < k; i++) {
		memcpy(backup, dis, sizeof(dis));
		for (int j = 0; j < m; j++) {
			int a = edge[j].a;
			int b = edge[j].b;
			int w = edge[j].w;
			dis[b] = min(dis[b], backup[a] + w);
		}
	}
	if (dis[n] > 0x3f3f3f3f / 2) {
		return -1;
	}
	return dis[n];
}
int main()
{
	cin >> n >> m >> k;
	for (int i = 0; i < m; i++) {
		int a, b, w;
		cin >> a >> b >> w;
		edge[i] = { a,b,w };
	}
	int ret = bellman_ford();
	if (ret == -1) {
		cout << "impossible" << endl;
	}
	else {
		cout << ret << endl;
	}
	return 0;
}